<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>投保人</title>
    <base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/"/>
    <link rel="icon" href="static/images/favicon.ico">
    <link rel="stylesheet" href="static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="static/css/layuimini.css" media="all">
    <link rel="stylesheet" href="static/css/themes/default.css" media="all">
    <link rel="stylesheet" href="static/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>投保人查询条件</legend>
</fieldset>

<form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form layui-form-pane">

    <blockquote class="layui-elem-quote">

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">投保人编号</label>
                <div class="layui-input-inline">
                    <input type="text" name="policyholdersId"  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">投保人姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="policyholdersName"  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">联系地址</label>
                <div class="layui-input-inline">
                    <input type="text" name="address"  autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center">
                <button type="button" class="layui-btn" lay-submit="doSearch" lay-filter="doSearch"><span class="layui-icon layui-icon-search"></span>查询</button>
                <button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh"></span>重置</button>
            </div>
        </div>

    </blockquote>

</form>
<table class="layui-hide" id="policyTable" lay-filter="policyTable"></table>

<div id="userRowBar" style="display: none;">
    <button type="button" lay-event="updateById"  class="layui-btn layui-btn-sm layui-btn-warm"><span class="layui-icon layui-icon-edit"></span>修改</button>

</div>

<div style="display: none" id="addOrUpdateDiv">
    <form action="" method="post" class="layui-form layui-form-pane" id="policyFrom" lay-filter="policyFrom" >
        <fieldset class="layui-elem-field layui-field-title">
            <legend>修改投保人</legend>
        </fieldset>
        <blockquote class="layui-elem-quote layui-quote-nm">
            <div class="layui-form-item">
                <label for="username2" class="layui-form-label"> <span
                        class="x-red">投保人姓名</span>
                </label>
                <div class="layui-input-inline">
                    <input type="hidden" name="policyholdersId">
                    <input type="text" id="username2" name="policyholdersName"
                           required="" lay-verify="required" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block" >
                    <input type="radio" name="sex" value="0" title="男" checked="">
                    <input type="radio" name="sex" value="1" title="女">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">证件类型</label>
                <div class="layui-input-inline">
                    <select name="credentialsType">
                        <option value="" selected="">-----------请选择-----------</option>
                        <option value="1" >身份证</option>
                        <option value="0" >军官证</option>
                    </select>
                </div>
                <label class="layui-form-label">证件号码</label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="credenId"
                           required="" lay-verify="required" autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-block">
                    <input type="text" id="aa" name="telephone" required=""
                           lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">联系地址</label>
                <div class="layui-input-block">
                    <input type="text" name="address" lay-verify="title"
                           autocomplete="off" placeholder="请输入地址" class="layui-input">
                </div>
            </div>

            <div class="layui-input-block" style="text-align: center">
                <button type="button" class="layui-btn" lay-submit="doSumbit" id="doSumbit" lay-filter="doSumbit"><span class="layui-icon layui-icon-add-1"></span>提交</button>
                <button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh"></span>重置</button>
            </div>
        </blockquote>
    </form>
</div>
<script type="text/javascript" src="/static/lib/layui-v2.5.5/layui.js"></script>


<script type="text/javascript">
    layui.use(['jquery','form','table','layer','laydate'],function() {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        var laydate = layui.laydate;

        //执行一个 table 实例
        //执行一个 table 实例
        var tableIns= table.render({
            elem: '#policyTable'
            ,url:'/dispatchedWorkerInfo/sqlpolicy'
            ,toolbar: true //开启头部工具栏，并为其绑定左侧模板
            ,title: '投保人信息查询'
            ,height:'full-250'
            ,page: false
            ,cols: [ [ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'policyholdersId', title: '投保人编号', sort: true, fixed: 'left'}
                ,{field: 'policyholdersName', title: '投保人姓名'}
                ,{field: 'sex', title: '性别',templet:function(d){
                        return d.sex==1?'<font color=blue>女</font>':'<font color=red>男</font>';
                    }}
                ,{field: 'credentialsType', title: '证件类型',templet:function(d){
                        return d.credentialsType==1?'<font color=blue>身份证</font>':'<font color=red>军官证</font>';
                    }}
                ,{field: 'credenId', title: '证件号码', sort: true, totalRow: true}
                ,{field: 'telephone', title: '联系电话'}
                ,{field: 'address', title: '联系地址'}
                ,{fixed: 'right', title:'操作', toolbar: '#userRowBar',align:'center'}

            ] ]
        });

        //模糊查询
        form.on("submit(doSearch)",function(data){
            console.log(data.field)
            tableIns.reload({
                where:data.field,
                page:{
                    curr:1
                }
            });
            return false;
        });

        //监听行事件
        table.on('tool(policyTable)', function(obj){
            var data = obj.data; //获得当前行数据
            switch(obj.event){
                case 'updateById':
                    updateById(data);
                    break;

            };
        });

        var mainIndex;
        var url;
        //打开修改弹出层
        function updateById(data){
            mainIndex=layer.open({
                type:1,
                content:$("#addOrUpdateDiv"),
                area:['800px','600px'],
                title:'修改投保人',
                success:function () {
                    $("#policyFrom")[0].reset();
                    form.val("policyFrom",data);
                    url="/policy/updatepolicy"
                }
            })
        }

        form.on("submit(doSumbit)",function (data) {
            $.post(url,data.field,function (res) {
                if (res.code==200){
                    tableIns.reload();
                }
                layer.msg(res.msg)
                layer.close(mainIndex);
            })
        })


    })
</script>
</body>
</html>